Page({
  data: {
    img: null,
    info: null,
    /*listCell: [
      {icon: '', iconColor: '', name: 'nickname'},
      {},
      {},
      {},
      {},
      {},
      {}
    ],*/
    uploadUrl: wx.util.interfaceUrl('common.upload.images')['url'],
    startYear: 1980,
    endYear: 2030,
    cancelColor: "#888",
    color: "#EB0909",
    rules: [
      {
        name: 'nickname',
        rule: ['required', 'isChinese', 'minLength: 2', 'maxLength: 6'],
        msg: ['请输入昵称', '昵称必须全部为中文', '昵称必须2-6个字符', '昵称必须2-6个字符']
      },
      /*{
        name: "mobile",
        rule: ["required", "isMobile"],
        msg: ["请输入手机号", "请输入正确的手机号"]
      }*/
    ]
  },
  onLoad: function () {
    this.datetime = this.selectComponent("#rf-datetime-ctx");
    this.setData({
      info: wx.getStorageSync('rf_member')
    });
  },
  imgUpload: function (e) {
    if (e.detail.status === 1) {
      this.setData({
        img: e.detail.imgArr[0] || null
      });
    }
  },
  mobile: function () {
    wx.util.toast('暂不支持，请联系客服');
  },
  selectDate: function () {
    this.datetime.show();
  },
  cofirmDate: function (e) {
    this.setData({
      birthday: e.detail.result
    });
  },
  update: function (e) {
    let formData = e.detail.value;
    formData.head_portrait = this.data.img || this.data.info.head_portrait;
    let chkRes = wx.form.validation(formData, this.data.rules);
    if (chkRes) {
      wx.util.toast(chkRes);
      return;
    }
    wx.util.request('user.info.modify', {
      query: `id=${this.data.info.id}`,
      body: formData
    }).then(res => {
      if (res == 'ok' || (res.id && res.id == this.info.id)) {
        wx.util.toast('已更新您的信息');
        setTimeout(() => {
          wx.navigateBack();
        }, 1500);
      }
    });
  }
})